<?php

  /**
   * This class implements getters to get every $_SERVER variables.<br />
   * 
   * @author Dany Mottier
   * @version 2.1
   */
  abstract class Server {

    /**
     * Array of arguments passed to script.<br />
     * @return array Array of arguments passed to script.
     */
    public static function getArguments() {
      return $_SERVER['argv'];
    }

    /**
     * Returns the number of arguments passed to the script if executed in
     * command line.<br />
     * @return integer Returns the number of arguments.
     */
    public static function countArguments() {
      return $_SERVER['argc'];
    }

    /**
     * The path to the running script, starting from the root path.<br />
     * @return string Returns the path to the running script.
     */
    public static function ScriptPath() {
      return $_SERVER['PHP_SELF'];
    }

    /**
     * The absolute path to the running script.<br />
     * This is equals to __FILE__ magic constant.
     * @return string Returns the absolute path to the running script.
     */
    public static function ScriptName() {
      return $_SERVER['SCRIPT_FILENAME'];
    }

    /**
     * Alias of ScriptName.<br />
     * @return string
     * @see ScriptName
     */
    public static function File() {
      return __FILE__;
    }

    /**
     * The name of the server, like 'localhost'.<br />
     * @return string The server name.
     */
    public static function Name() {
      return $_SERVER['SERVER_NAME'];
    }

    /**
     * The revision number of the CGI interface.<br />
     * @return string Returns the revision number.
     */
    public static function Revision() {
      return $_SERVER['GATEWAY_INTERFACE'];
    }

    /**
     * The identification string sent in headers when the server replies to 
     * requests.<br />
     * @return string Returns the identification string.
     */
    public static function Software() {
      return $_SERVER['SERVER_SOFTWARE'];
    }

    /**
     * Name and revision of the communication protocol.<br />
     * @return string Returns the name and revision of the communication protocol.
     */
    public static function Protocol() {
      return $_SERVER['SERVER_PROTOCOL'];
    }

    /**
     * The request method used to access the page.<br />
     * @return string Returns the request method used to access the page.
     */
    public static function RequestMethod() {
      return $_SERVER['REQUEST_METHOD'];
    }

    /**
     * The unix time since the beginning of the request.<br />
     * @return integer Returns the unix time.
     */
    public static function RequestTime() {
      return $_SERVER['REQUEST_TIME'];
    }

    /**
     * Returns the query string.<br />
     * @return string Returns the query string.
     */
    public static function QueryString() {
      return $_SERVER['QUERY_STRING'];
    }

    /**
     * Returns an array with every pair key / value.<br />
     * @return array Returns an array with every pair key / value.
     */
    public static function ParseQueryString() {
      $array = array();
      $params = explode("&", Server::QueryString());

      for ($i = 0; $i < count($params); ++$i) {
        $values = explode("=", $params[$i]);
        $array[$values[0]] = $values[1];
      }

      return $array;
    }

    /**
     * The request string used to access the script if set.<br />
     * @return string The request string.
     */
    public static function Root() {
      return $_SERVER['DOCUMENT_ROOT'];
    }

    /**
     * The content of the accept header in the current request if set.<br />
     * @return string The content of the accept header.
     */
    public static function HttpAccept() {
      return $_SERVER['HTTP_ACCEPT'];
    }

    /**
     * Te content of the accept charset header in the current request if set.<br />
     * @return string Te content of the accept charset header.
     */
    public static function HttpAcceptCharset() {
      return $_SERVER['HTTP_ACCEPT_CHARSET'];
    }

    /**
     * The content of the accept encoding header in the current request if set.<br />
     * @return string The content of the accept encoding header.
     */
    public static function HttpAcceptEncoding() {
      return $_SERVER['HTTP_ACCEPT_ENCODING'];
    }

    /**
     * The content of the accept language header in the current request if set.<br />
     * @return string The content of the accept language header.
     */
    public static function HttpAcceptLanguage() {
      return $_SERVER['HTTP_ACCEPT_LANGUAGE'];
    }

    /**
     * The content of the connection header in the current request if set.<br />
     * @return string The content of the connection header.
     */
    public static function HttpConnection() {
      return $_SERVER['HTTP_CONNECTION'];
    }

    /**
     * The content of the host header in the current request if set.<br />
     * @return string The content of the host header.
     */
    public static function HttpHost() {
      return $_SERVER['HTTP_HOST'];
    }

    /**
     * The url of the previous page of the current if exists.<br />
     * @return string The url of the previous page.
     */
    public static function HttpReferer() {
      if (!empty($_SERVER['HTTP_REFERER']))
        return $_SERVER['HTTP_REFERER'];
      else
        return NULL;
    }

    /**
     * The content of the user-agent header in the current request if set.<br />
     * @return string The content of the user-agent header.
     */
    public static function HttpUserAgent() {
      return $_SERVER['HTTP_USER_AGENT'];
    }

    /**
     * Set to True if the script must be executed in https mode.<br />
     * @param boolean $https TRUE if the script is executed in https mode.
     * @return boolean True if Https variable is set.
     */
    public static function Https($https = FALSE) {
      if (Validator::Validate($https, Validator::BOOLEAN))
        if ($https)
          $_SERVER['HTTPS'] = TRUE;
        else
        if (!empty($_SERVER['HTTPS']))
          return $_SERVER['HTTPS'];
        else
          return NULL;
    }

    /**
     * The IP address of the client.<br />
     * @return string The IP address.
     */
    public static function RemoteIP() {
      return $_SERVER['REMOTE_ADDR'];
    }

    /**
     * The hostname of the client.<br />
     * @return string The hostname.
     */
    public static function RemoteHost() {
      if (!empty($_SERVER['REMOTE_HOST']))
        return $_SERVER['REMOTE_HOST'];
      else
        return NULL;
    }

    /**
     * The port number used by the client.<br />
     * @return int The port number.
     */
    public static function RemotePort() {
      return $_SERVER['REMOTE_PORT'];
    }

    /**
     * The email address of the server administrator.<br />
     * @return string The email address.
     */
    public static function Administrator() {
      return $_SERVER['SERVER_ADMIN'];
    }

    /**
     * The port used to listen by the server.<br />
     * @return integer The port used.
     */
    public static function Port() {
      return $_SERVER['SERVER_PORT'];
    }

    /**
     * The version number of the server and the virtual hostname added to 
     * generated pages if the option is used.<br />
     * @return string The version number of the server.
     */
    public static function Signature() {
      return $_SERVER['SERVER_SIGNATURE'];
    }

    /**
     * The path to the current script.<br />
     * @return string The path to the current script.
     */
    public static function PathTranslated() {
      if (!empty($_SERVER['PATH_TRANSLATED']))
        return $_SERVER['PATH_TRANSLATED'];
      else
        return NULL;
    }

    /**
     * The uri used to access this page.<br />
     * @return string The uri.
     */
    public static function RequestUri() {
      return $_SERVER['REQUEST_URI'];
    }

    /**
     * The authentication method.<br />
     * @return string The authentication method.
     */
    public static function AuthenticationDigest() {
      if (!empty($_SERVER['PHP_AUTH_DIGEST']))
        return $_SERVER['PHP_AUTH_DIGEST'];
      else
        return NULL;
    }

    /**
     * The username used to authenticate.<br />
     * @return string The username used to authenticate.
     */
    public static function AuthenticationUser() {
      if (!empty($_SERVER['PHP_AUTH_USER']))
        return $_SERVER['PHP_AUTH_USER'];
      else
        return NULL;
    }

    /**
     * The password used to authenticate.<br />
     * @return string The password used to authenticate.
     */
    public static function AuthenticationPassword() {
      if (!empty($_SERVER['PHP_AUTH_PW']))
        return $_SERVER['PHP_AUTH_PW'];
      else
        return NULL;
    }

    /**
     * The authentication type used to access the current script if set.<br />
     * @return string The authentication type.
     */
    public static function AuthenticationType() {
      if (!empty($_SERVER['PHP_AUTH_TYPE']))
        return $_SERVER['PHP_AUTH_TYPE'];
      else
        return NULL;
    }

    /**
     * Gets the current PHP version.
     * @return String The current PHP version.
     */
    public static function getPhpVersion() {
      return new String(phpversion());
    }

  }

?>
